<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name ="viewport" content ="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <!--<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>-->
    <script src="https://res2.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
    <script src="./js/date.js"></script>
    <title>online门诊</title>
    <script type="text/javascript">
        /*必须在加载vue前进行判断 否则会先加载完index页面后进入授权页，影响视觉效果*/
        console.log("init index.html begin");
        let qsParse = function (url) {
            if (!url.includes("?")) {
                return {};
            }
            let arr1 = url.split("?");
            let params = arr1[1].split("&");
            let obj = {};//声明对象
            for (let i = 0; i < params.length; i++) {
                let param = params[i].split("=");
                obj[param[0]] = param[1];//为对象赋值
            }
            return obj;
        };

        let qsobj = qsParse(window.location.href.split("#")[0]);

        console.log(qsobj);

        if (qsobj.orderNo) {
            window.localStorage.setItem("orderNo", qsobj.orderNo.split("#/")[0]);
        }
        if (qsobj.openid) {
            /*因为在这个时候无法获取到vue组件对象，借助localStorage存储对象或者vue的created中重新解析url*/
            window.localStorage.setItem("openid", qsobj.openid.split("#/")[0]);
        } else {
            if (!qsobj.openid) {
                console.log("微信授权");
                // 微信授权,开发阶段暂时注释掉代码
                debugger;
                window.location.href = "http://api.51self-service.cn/wx/authorize?returnUrl=" + encodeURIComponent(window.location.href);
            }
        }

        let hashUrl = window.location.href.split("#")[1];
        console.log(hashUrl);

        if (!(hashUrl.length > 1 || hashUrl == "/home")) {
            console.log("=======home========");
            window.location.href = window.location.href.split("#")[0];
        }

        /*pushHistory();
        window.addEventListener("popstate", function (e) {
            alert("我监听到了浏览器的返回按钮事件啦");//根据自己的需求实现自己的功能
        }, false);

        function pushHistory() {
            var state = {
                title: "title",
                url: "#"
            };
            window.history.pushState(state, "title", "#");
        }*/

        console.log("init index.html end");
    </script>
</head>
<body>
<noscript>
    <strong>We're sorry but health doesn't work properly without JavaScript enabled. Please enable it to
        continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
